/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SolvedProblems;

//555 
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author InspireServe
 */
class Main_555 {
    public static HashMap<String, Integer> cardToNumber = new HashMap<String, Integer>();
    public static HashMap<Integer, String> numberToCard = new HashMap<Integer, String>();
    public static HashMap<String, Integer> playerToInteger = new HashMap<String, Integer>();
    
    public static String[] cards = {"2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A"};
    public static String[] suits = {"C" , "D", "S", "H"};
    
    public static String[] playerString = {"S", "W", "N", "E"};
    public static int[][] players = new int[4][13]; //s w n e

    //public static void main(String args[]) throws FileNotFoundException{
    public static void initialize(){
        int cardIntegerValue = 0;
        for(int suitNumber =0; suitNumber < 4; suitNumber++){
            String suitSign = suits[suitNumber];
            for(int cardNumber = 0; cardNumber < 13; cardNumber++){
                String card =  suitSign + cards[cardNumber];
                cardToNumber.put(card, cardIntegerValue);
                numberToCard.put(cardIntegerValue, card);
                cardIntegerValue++;
            }//end for
        }//end for
        
        playerToInteger.put("S", 0);
        playerToInteger.put("W", 1);
        playerToInteger.put("N", 2);
        playerToInteger.put("E", 3);        
        //printf(" " + cardToNumber.size());
        //printf(" " + numberToCard.size());
    }//end of initialize
    
    public static void dealCards(String str, int dealer){
        LinkedList<String> test = new LinkedList<String>();
        int currentGetter = (dealer + 1) % 4;
        for(int start = 0; start < 52; start += 1){
            String card = str.substring(2 * start, 2 * start + 2);
            int cardPlaceIndex = start / 4;
         //   printf("" + currentGetter + " " + cardPlaceIndex);
            //int i = cardToNumber.get(card);
            players[currentGetter][cardPlaceIndex] = cardToNumber.get(card);
            //players[currentGetter][cardPlaceIndex] = i;
            currentGetter = (currentGetter + 1) % 4;
            //test.add(card);
        }
        //printf(test.toString());
        //printf(test.size() + "");
       // printf(players.toString());
        int j = 0;
    }//end of deal cards
    
    public static void main(String args[]) throws IOException{
        //String str = "CQDTC4D8S7HTDAH7D2S3D6C6S6D9S4SAD7H2CKH5D3CTS8C9H3C3DQS9SQDJH8HAS2SKD4H4S5C7SJC8DKC5C2CAHQCJSTH6HKH9D5HJ";
        initialize();
        
        //test();
        run();
    }//end of main
    
    //public static void run()throws FileNotFoundException{
    public static void run() throws IOException{
        //take input
        //Scanner lineReader = new Scanner(System.in);
        //BufferedReader lineReader = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
        BufferedReader lineReader = new BufferedReader(new InputStreamReader(System.in));
        //Scanner lineReader = new Scanner(new File("input.txt"));
        //Scanner valueReader;
        String line;
        //start
        while (true) {
            //if it is a deal then it should start with dealer
            //otherwise it is the end and starts with #
            line = lineReader.readLine();
            if(line.trim().startsWith("#")){
                break;
            }
            //line = lineReader.readLine(); //get dealer
            int dealer = playerToInteger.get(line);
            
            //read cards
            String cards = lineReader.readLine() + lineReader.readLine();
            
            dealCards(cards, dealer);
            for (int i = 0; i < 4; i++) {
                //Collections.sort();
                Arrays.sort(players[i]);
            }//end for
            //for (int[] userCards : players) {
            for(int playerNumber = 0; playerNumber < 4; playerNumber++){
                String allUserCards = playerString[playerNumber] + ":";
                for (int cardNumber : players[playerNumber]) {
                    allUserCards = allUserCards + " " + numberToCard.get(cardNumber);
                }
                printf(allUserCards);
            }
            //valueReader = new StringTokenizer(line);
        }//end while
        
        /*
         int numberOfTestCases = Integer.parseInt(lineReader.readLine());
         for(int i = 0; i < numberOfTestCases; i++){
        
         }//end for
         */
    }//end of run
    
    public static void test(){
        List<Integer> testInt = new LinkedList<Integer>();
        testInt.add(1);
        testInt.add(5);
        testInt.add(0);
        testInt.add(4);
        
        Collections.sort(testInt);
        System.out.println(testInt);
    }//end of test
    
    public static void printf(String str){
        System.out.println(str);
    }//end of printf
}//end of class
